/*
 * @Descripttion: 胡腾辉 | feico
 * @version: V1.0
 * @Author: feico
 * @Date: 2022-02-20 12:04:09
 * @LastEditors: feico
 * @LastEditTime: 2022-02-22 15:03:45
 */
import { setToken,delToken } from '../../utils'
import request from '../../utils/request'
import { LOGIN_LOGIN, LOGOUT } from '../constants'

export const loginAc=(token)=>({
    type:LOGIN_LOGIN,
    token
})
export const logoutAc=()=>({type:LOGOUT})


// 登录请求
export const login = (payload)=>{
    return async(dispatch)=>{
        const { data: { data:{token} } }= await request.post('/authorizations',payload)
        setToken(token)
        dispatch(loginAc(token))
    }
}

// 退出请求
export const logout=()=>{
    return (dispatch)=>{
        delToken()
        dispatch(logoutAc)
    }   
}